rm -f /usr1/EcmaCI/shell/262Test/ark_ts2abc_build.log
rm -f /usr1/EcmaCI/shell/262Test/ets_frontend_build.log
rm -f /usr1/EcmaCI/shell/262Test/ts2abc_c_release_failed262.txt
rm -f /usr1/EcmaCI/shell/262Test/ts2abc_c_debug_failed262.txt
rm -f /usr1/EcmaCI/shell/262Test/es2panda_c_debug_failed262.txt
rm -f /usr1/EcmaCI/shell/262Test/ts2abc_asm_release_failed262.txt
rm -f /usr1/EcmaCI/shell/262Test/ts2abc_asm_debug_failed262.txt
rm -f /usr1/EcmaCI/shell/262Test/es2panda_asm_debug_failed262_asm.txt
rm -f /usr1/EcmaCI/shell/262Test/report.txt
rm -f /usr1/EcmaCI/shell/262Test/summary_ts2abc_c_debug.txt
rm -f /usr1/EcmaCI/shell/262Test/summary_ts2abc_c_release.txt
rm -f /usr1/EcmaCI/shell/262Test/summary_es2panda_c_debug.txt
rm -f /usr1/EcmaCI/shell/262Test/summary_ts2abc_asm_release.txt
rm -f /usr1/EcmaCI/shell/262Test/summary_ts2abc_asm_debug.txt
rm -f /usr1/EcmaCI/shell/262Test/summary_es2panda_asm_debug.txt
rm -f /usr1/EcmaCI/shell/262Test/benchmark.txt
rm -f /usr1/EcmaCI/shell/262Test/5000class.txt 
rm -f /usr1/EcmaCI/shell/262Test/5000class_new.txt 

cat /usr1/EcmaCI/shell/262Test/header.preset >> /usr1/EcmaCI/shell/262Test/report.txt ### build header ###
##################################################################################################################
#                                     get commit info
##################################################################################################################
cd /usr1/EcmaCI/openharmony-master
rm -rf out/
rm -rf /usr1/EcmaCI/openharmony-master/arkcompiler/ets_frontend/ts2panda/node_modules
cp /usr1/EcmaCI/shell/262Test/build_commit_table.template /usr1/EcmaCI/shell/262Test/build_commit_table.wip
/usr1/EcmaCI/shell/262Test/get_last_commit_id.sh
repo forall -c 'git clean -ffdx'
repo forall -c 'git reset --hard HEAD'
repo sync --force-sync -c --jobs 32
repo forall -c 'git lfs pull'
./build/prebuilts_download.sh > /usr1/EcmaCI/shell/262Test/prebuilts_download_result
/usr1/EcmaCI/shell/262Test/get_current_commit_id.sh

cat /usr1/EcmaCI/shell/262Test/build_commit_table.wip >> /usr1/EcmaCI/shell/262Test/report.txt ### build commit table ####
##################################################################################################################
if [ ! -d /usr1/EcmaCI/openharmony-master/arkcompiler/ets_frontend/ts2panda/node_modules ];
then
    ./build/prebuilts_download.sh > /usr1/EcmaCI/shell/262Test/prebuilts_download_result
fi

##################################################################################################################
#                                             run 262 tests
##################################################################################################################
cp /usr1/EcmaCI/shell/262Test/build_summary_table.template /usr1/EcmaCI/shell/262Test/build_summary_table.wip

###################################################
# disable asm interpreter
cd arkcompiler/ets_frontend
git apply /usr1/EcmaCI/shell/262Test/c.diff
###################################################
#----------------------------------------------------------------------------------------------------------------#
#                                              ts2abc  c release                                                 #
#----------------------------------------------------------------------------------------------------------------#
cd /usr1/EcmaCI/openharmony-master
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ark_ts2abc_build > /usr1/EcmaCI/shell/262Test/ark_ts2abc_build.log

cd arkcompiler/ets_frontend
python3 test262/run_test262.py --es2021 all --timeout 180000 --libs-dir ../../out/rk3568/clang_x64/ark/ark:../../out/rk3568/clang_x64/ark/ark_js_runtime:../../out/rk3568/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-binary=../../out/rk3568/clang_x64/ark/ark/build/src/index.js > /usr1/EcmaCI/shell/262Test/run262_ts2abc_c_release.log 

tail -n 8 /usr1/EcmaCI/shell/262Test/run262_ts2abc_c_release.log >> /usr1/EcmaCI/shell/262Test/summary_ts2abc_c_release.txt
#----------------------------------------------------------------------------------------------------------------#
#                                              ts2abc  c debug                                                   #
#----------------------------------------------------------------------------------------------------------------#
cd /usr1/EcmaCI/openharmony-master
# speed up for debug test
sed -i 's/\([^a-z]\)-O0/\1-O2/' /usr1/EcmaCI/openharmony-master/arkcompiler/ets_runtime/BUILD.gn
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ark_ts2abc_build --gn-args is_debug=true

cd arkcompiler/ets_frontend
python3 test262/run_test262.py --es2021 all --timeout 180000 --libs-dir ../../out/rk3568/clang_x64/lib.unstripped/clang_x64/ark/ark:../../out/rk3568/clang_x64/lib.unstripped/clang_x64/ark/ark_js_runtime:../../out/rk3568/clang_x64/lib.unstripped/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/rk3568/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-binary=../../out/rk3568/clang_x64/ark/ark/build/src/index.js > /usr1/EcmaCI/shell/262Test/run262_ts2abc_c_debug.log 

tail -n 8 /usr1/EcmaCI/shell/262Test/run262_ts2abc_c_debug.log >> /usr1/EcmaCI/shell/262Test/summary_ts2abc_c_debug.txt
#----------------------------------------------------------------------------------------------------------------#
#                                              es2panda  c debug                                                 #
#----------------------------------------------------------------------------------------------------------------#
cd /usr1/EcmaCI/openharmony-master
# speed up for debug test
sed -i 's/\([^a-z]\)-O0/\1-O2/' /usr1/EcmaCI/openharmony-master/arkcompiler/ets_runtime/BUILD.gn
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ets_frontend > /usr1/EcmaCI/shell/262Test/ets_frontend_build.log

cd arkcompiler/ets_frontend
python3 test262/run_test262.py --es2021 all --timeout 180000 --libs-dir ../../out/rk3568/clang_x64/lib.unstripped/clang_x64/ark/ark:../../out/rk3568/clang_x64/lib.unstripped/clang_x64/ark/ark_js_runtime:../../out/rk3568/clang_x64/lib.unstripped/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/rk3568/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-binary=../../out/rk3568/clang_x64/ark/ark/es2abc --merge-abc-binary=../../out/rk3568/clang_x64/ark/ark/merge_abc --ark-frontend=es2panda > /usr1/EcmaCI/shell/262Test/run262_es2panda_c_debug.log

tail -n 8 /usr1/EcmaCI/shell/262Test/run262_es2panda_c_debug.log >> /usr1/EcmaCI/shell/262Test/summary_es2panda_c_debug.txt


#----------------------------------------------------------------------------------------------------------------#
#                                              ts2abc  asm release                                               #
#----------------------------------------------------------------------------------------------------------------#
cd /usr1/EcmaCI/openharmony-master
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ark_ts2abc_build

cd arkcompiler/ets_frontend
python3 test262/run_test262.py --es2021 all --timeout 180000 --libs-dir ../../out/rk3568/clang_x64/ark/ark:../../out/rk3568/clang_x64/ark/ark_js_runtime:../../out/rk3568/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-binary=../../out/rk3568/clang_x64/ark/ark/build/src/index.js > /usr1/EcmaCI/shell/262Test/run262_ts2abc_asm_release.log

tail -n 8 /usr1/EcmaCI/shell/262Test/run262_ts2abc_asm_release.log >> /usr1/EcmaCI/shell/262Test/summary_ts2abc_asm_release.txt


###################################################
# reset c.diff
cd arkcompiler/ets_frontend
git checkout HEAD -- test262/run_sunspider.py
###################################################
#----------------------------------------------------------------------------------------------------------------#
#                                              ts2abc  asm debug                                                 #
#----------------------------------------------------------------------------------------------------------------#
cd /usr1/EcmaCI/openharmony-master
# speed up for debug test
sed -i 's/\([^a-z]\)-O0/\1-O2/' /usr1/EcmaCI/openharmony-master/arkcompiler/ets_runtime/BUILD.gn
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ark_ts2abc_build --gn-args is_debug=true

cd arkcompiler/ets_frontend
python3 test262/run_test262.py --es2021 all --timeout 180000 --libs-dir ../../out/rk3568/clang_x64/lib.unstripped/clang_x64/ark/ark:../../out/rk3568/clang_x64/lib.unstripped/clang_x64/ark/ark_js_runtime:../../out/rk3568/clang_x64/lib.unstripped/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/rk3568/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-binary=../../out/rk3568/clang_x64/ark/ark/build/src/index.js > /usr1/EcmaCI/shell/262Test/run262_ts2abc_asm_debug.log

tail -n 8 /usr1/EcmaCI/shell/262Test/run262_ts2abc_asm_debug.log >> /usr1/EcmaCI/shell/262Test/summary_ts2abc_asm_debug.txt
#----------------------------------------------------------------------------------------------------------------#
#                                              es2panda  asm debug                                               #
#----------------------------------------------------------------------------------------------------------------#
cd /usr1/EcmaCI/openharmony-master
# speed up for debug test
sed -i 's/\([^a-z]\)-O0/\1-O2/' /usr1/EcmaCI/openharmony-master/arkcompiler/ets_runtime/BUILD.gn
./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages --build-target ets_frontend #--gn-args is_debug=true

cd arkcompiler/ets_frontend
python3 test262/run_test262.py --es2021 all --timeout 180000 --libs-dir ../../out/rk3568/clang_x64/lib.unstripped/clang_x64/ark/ark:../../out/rk3568/clang_x64/lib.unstripped/clang_x64/ark/ark_js_runtime:../../out/rk3568/clang_x64/lib.unstripped/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/rk3568/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-binary=../../out/rk3568/clang_x64/ark/ark/es2abc --merge-abc-binary=../../out/rk3568/clang_x64/ark/ark/merge_abc --ark-frontend=es2panda > /usr1/EcmaCI/shell/262Test/run262_es2panda_asm_debug.log


tail -n 8 /usr1/EcmaCI/shell/262Test/run262_es2panda_asm_debug.log >> /usr1/EcmaCI/shell/262Test/summary_es2panda_asm_debug.txt

##################################################################################################################
#                                     5000 class 
##################################################################################################################
cd /usr1/EcmaCI/openharmony-master/out/rk3568/clang_x64/ark/ark/build/
npm install
cd /usr1/EcmaCI/shell/262Test/5000Classes
./runCommand.sh import5000.js &> /usr1/EcmaCI/shell/262Test/5000class.txt 
./runCommand.sh import5000_new.js &> /usr1/EcmaCI/shell/262Test/5000class_new.txt 
cd -

##################################################################################################################
#                                      benchmark 
##################################################################################################################
cd /usr1/EcmaCI/shell/262Test/benchmark_x64/
./test.sh > /usr1/EcmaCI/shell/262Test/benchmark.txt 
cd -

#################################################################################################################
#                                      build result
#################################################################################################################
/usr1/EcmaCI/shell/262Test/build_summary.sh
cat /usr1/EcmaCI/shell/262Test/build_summary_table.wip >> /usr1/EcmaCI/shell/262Test/report.txt ### build summary table ###

cat /usr1/EcmaCI/shell/262Test/tail.preset >> /usr1/EcmaCI/shell/262Test/report.txt ### build tail ####


cat /usr1/EcmaCI/shell/262Test/run262_ts2abc_c_release.log | grep "FAIL test262/data" -A 3 >> /usr1/EcmaCI/shell/262Test/ts2abc_c_release_failed262.txt
cat /usr1/EcmaCI/shell/262Test/run262_ts2abc_c_debug.log | grep "FAIL test262/data" -A 3 >> /usr1/EcmaCI/shell/262Test/ts2abc_c_debug_failed262.txt
cat /usr1/EcmaCI/shell/262Test/run262_es2panda_c_debug.log | grep "FAIL test262/data" -A 3 >> /usr1/EcmaCI/shell/262Test/es2panda_c_debug_failed262.txt
cat /usr1/EcmaCI/shell/262Test/run262_ts2abc_asm_release.log | grep "FAIL test262/data" -A 3 >> /usr1/EcmaCI/shell/262Test/ts2abc_asm_release_failed262.txt
cat /usr1/EcmaCI/shell/262Test/run262_ts2abc_asm_debug.log | grep "FAIL test262/data" -A 3 >> /usr1/EcmaCI/shell/262Test/ts2abc_asm_debug_failed262.txt
cat /usr1/EcmaCI/shell/262Test/run262_es2panda_asm_debug.log | grep "FAIL test262/data" -A 3 >> /usr1/EcmaCI/shell/262Test/es2panda_asm_debug_failed262_asm.txt

git checkout .


##################################################################################################################
#                                      send email
##################################################################################################################
cat /usr1/EcmaCI/shell/262Test/report.txt | mutt -s "openharmony master 262 test report" -e "set content_type=text/html"\
	-a /usr1/EcmaCI/shell/262Test/prebuilts_download_result\
	-a /usr1/EcmaCI/shell/262Test/ark_ts2abc_build.log\
	-a /usr1/EcmaCI/shell/262Test/ets_frontend_build.log\
	-a /usr1/EcmaCI/shell/262Test/ts2abc_c_release_failed262.txt\
        -a /usr1/EcmaCI/shell/262Test/ts2abc_c_debug_failed262.txt\
	-a /usr1/EcmaCI/shell/262Test/es2panda_c_debug_failed262.txt\
	-a /usr1/EcmaCI/shell/262Test/ts2abc_asm_release_failed262.txt\
	-a /usr1/EcmaCI/shell/262Test/ts2abc_asm_debug_failed262.txt\
	-a /usr1/EcmaCI/shell/262Test/es2panda_asm_debug_failed262_asm.txt -- `cat /usr1/EcmaCI/shell/262Test/recipients`
##################################################################################################################
